﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using ServerYuGi.PythonRegister;

namespace ServerYuGi.CardScriptDatabase
{
    public class CardScriptDB
    {
        Dictionary<int, CardScript> DatabaseScript = new Dictionary<int, CardScript>();
        public CardScriptDB()
        {

        }
        public void LoadAllScript(string path)
        {
            string[] files = Directory.GetFiles(path);
            foreach (string item in files)
            {
                FileInfo f = new FileInfo(item);
                if (!f.Extension.Equals(".xml"))
                    continue;
                string s = f.Name.Remove(f.Name.Length - 4, 4);
                int id =Convert.ToInt32( s.Substring(1, s.Length - 1));
                CardScript i = CardScript.Load(item);
                DatabaseScript.Add(id, i);
            }
            
        }
        public CardScript GetScript(int ID)
        {
            bool isTrue = false;
            List<int> ListKey = DatabaseScript.Keys.ToList();
            for (int i = 0; i < ListKey.Count;i++ )
            {
                if (ListKey[i] == ID)
                {
                    isTrue = true;
                    break;
                }
            }
            if (isTrue)
                return DatabaseScript[ID];
            return null;
        }
    }
}
